<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="search-container">
        <el-input v-model="listQuery.title" placeholder="请输入内容" style="width: 240px;margin-right:10px;" class="filter-item" @keyup.enter.native="handleFilter" />
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
          查询
        </el-button>
      </div>
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :layout="'total, sizes, prev, pager, next, jumper'" :limit.sync="listQuery.pageSize" @pagination="getManageDatas" />
    </div>

    <el-table
      :key="tableKey"
      v-loading="pageLoading"
      :data="listData"
      border
      fit
      style="width: 100%;"
    >
      <el-table-column label="名称" align="center">
        <template slot-scope="{row}">
          <span>{{ row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="任务" align="center">
        <template slot-scope="{row}">
          <span>{{ row.task.done }} / {{ row.task.total }}</span>
        </template>
      </el-table-column>
      <el-table-column label="需求" align="center">
        <template slot-scope="{row}">
          <span>{{ row.demand.done }} / {{ row.demand.total }}</span>
        </template>
      </el-table-column>
      <el-table-column label="缺陷" align="center">
        <template slot-scope="{row}">
          <span>{{ row.defect.done }} / {{ row.defect.total }}</span>
        </template>
      </el-table-column>
      <el-table-column label="逾期" align="center">
        <template slot-scope="{row}">
          <span>{{ row.overdue }}</span>
        </template>
      </el-table-column>
      <el-table-column label="负责人" align="center">
        <template slot-scope="{row}">
          <span>{{ row.head && row.head.nickname }}</span>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import * as ManageApi from '@/api/manage'

export default {
  name: 'Dashboard',
  components: { Pagination },
  data() {
    return {
      tableKey: 0,
      total: 0,
      pageLoading: false,
      listQuery: {
        pageNo: 1,
        pageSize: 10
      },
      listData: []
    }
  },
  mounted() {
    this.getManageDatas()
  },
  methods: {
    async getManageDatas(pageQuery) {
      if (pageQuery) {
        this.listQuery = Object.assign(this.listQuery, pageQuery)
      }
      this.listData = []
      this.pageLoading = true
      const { data } = await ManageApi.getManageProjects(this.listQuery)
      if (data && data.total) {
        this.listData = data.items
        this.total = data.total
      }
      this.pageLoading = false
    },
    handleFilter() {
      this.listQuery.pageNo = 1
      this.getManageDatas()
    }
  }
}
</script>

<style scoped>
.filter-container {
  display: flex;
  justify-content: space-between;
}
.pagination {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}
</style>
